﻿#pragma once
#include "AsQBasicGlobal.h"

__AS_JY(Update 2022)
template <typename _HostType>
class AsBinder {

protected:
	AsBinder(_HostType* host) : host(host) {}
	_HostType* host;

public:
	template <typename _Signal, typename _Slot>
	void bindSignal(_Signal signal, _Slot slot) {
		QObject::connect(host, signal, host, slot, Qt::DirectConnection);
	}

	template <typename _Signal, typename _Slot>
	void bindSignal(_Signal signal, const QObject* context, _Slot slot, Qt::ConnectionType type = Qt::AutoConnection) {
		QObject::connect(host, signal, context, slot);
	}

	template <typename _Signal, typename _Slot>
	void bindSignal(_Signal signal, const typename QtPrivate::FunctionPointer<_Slot>::Object* receiver, _Slot slot, Qt::ConnectionType type = Qt::AutoConnection) {
		QObject::connect(host, signal, receiver, slot);
	}

	template <typename _Signal, typename _Slot>
	void unbindSignal(_Signal signal, const QObject* context, _Slot slot) {
		QObject::disconnect(host, signal, context, slot);
	}

	template <typename _Signal, typename _Slot>
	void unbindSignal(_Signal signal, const typename QtPrivate::FunctionPointer<_Slot>::Object *receiver, _Slot slot) {
		QObject::disconnect(host, signal, receiver, slot);
	}

	void unbindSignal(const QObject* receiver) {
		QObject::disconnect(host, 0, receiver, 0);
	}

	void unbindSignal(const char* signal) {
		host->disconnect(signal);
	}

	void unbindSignals() {
		host->disconnect();
	}

};
